﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UserForms
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var name = textBox1.Text;
            var pwd = textBox2.Text;




            if (textBox1.Text.Length != 0 && textBox2.Text.Length != 0 && textBox3.Text.Length != 0)//判断是否输入内容
            {
                if (textBox2.Text == textBox3.Text)//判断两次输入的密码是否正确
                {

                    string sql = string.Format("select * from Student0002 where s_name='{0}' and s_pwd='{1}'", name, pwd);

                    DataTable mytable = ADOopertion.Select(sql);


                    var myrow = mytable.Rows.Count;


                    if (myrow == 1)//判断是否存在用户名和密码都相同的用户
                    {

                        MessageBox.Show("已存在用户名！！");
                    }
                    else
                    {
                        string sql2 = string.Format("insert into Student0002 values('{0}','{1}')", name, pwd);

                        var n = ADOopertion.DeleteUpdateInsert(sql2);

                        if (n >= 1)
                        {
                            MessageBox.Show("注册成功");
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("注册失败");
                        }
                    }


                }
                else
                {
                    MessageBox.Show("两次输入的密码不正确");

                    textBox2.Clear();
                    textBox3.Clear();
                }


            }
            else
            {
                MessageBox.Show("请填完全信息，谢谢");
            }





        }
    }
}
